<?php
session_start();
include('Util/Util.php');
include('Classes/UI/UI.php');
include('Classes/Account.php');
include('Classes/NationState.php');
$account = new Account();
$nationState = new NationState();
display('header');
?>
    <body>
    <style type="text/css">
        #ul1, #ul2, #ul3 {
            display:none;
        }
    </style>
    <script type="text/javascript">
        function show(item) {
            if (document.getElementById(item).style.display == 'block') {
                document.getElementById(item).style.display = 'none';
            } else {
                document.getElementById(item).style.display = 'block';
            }
        }
    </script>

        <table border="1" width="100%" height="700" cellpadding="5">
            <tr>
                <td width="20%" valign="top">
                    NAVIGATION<br />
                    <ul>
                        <li><a href="javascript:show('ul1');">Nation Overview</a></li>
                        <ul id="ul1">
                        <li><a href="?dest=changeNation">Change Nation Name</a></li>
                        <li><a href="?dest=setFlag">Set Flag</a></li>
                        <li><a href="?dest=changeSlogan">Change Slogan</a></li>
                        </ul>
                        <li><a href="javascript:show('ul2');">Federal Government</a></li>
                        <ul id="ul2">
                        <li><a href="?dest=setTaxRate">Set Tax Rate</a></li>
                        <li><a href="?dest=setSpending">Set Spending</a></li>
                        </ul>
                        <li><a href="javascript:show('ul3');">Federal Bank</a></li>
                        <ul id="ul3">
                        <li><a href="?dest=setInterestRate">Set Interest Rate</a></li>
                        <li><a href="?dest=buySellBonds">Buy/Sell Bonds</a></li>
                        <li><a href="?dest=setReserveRatio">Set Reserve Ratio</a></li>
                        </ul>
                    </ul>
                </td>
                
                <td width="80%" valign="top">
                    <?php

                        if(isset($_GET['dest'])){
                            echo 'Dest is set, displaying other page.';
                            echo '</br>';
                            $input = $_GET['dest'];
                            $UI = new UI();
                            if($input == 'changeNation'){
                                $UI->displayChangeNationName();
                            }else if($input == 'setFlag'){
                                $UI->displaySetFlag();
                            }else if($input == 'changeSlogan'){
                                $UI->displayChangeSlogan();
                            }else if($input == 'setTaxRate'){
                                $UI->displaySetTaxRate();
                            }else if($input == 'setSpending'){
                                $UI->displaySetSpending();
                            }else if($input == 'setInterestRate'){
                                $UI->displaySetInterestRate();
                            }else if($input == 'buySellBonds'){
                                $UI->displayBuySellBonds();
                            }else if($input == 'setReserveRatio'){
                                $UI->displaySetReserveRatio();
                            }else{
                                echo 'Input in url is invalid';
                            }
                            echo '</br>';
                        }

			$nationId = -1;

			if(isset($_SESSION['user'])){
				echo 'User session variable is set, storing id.';
                                $nationId = $account->getID($_SESSION['user']);
                        }

                        if(isset($_POST['interestRate'])){
                            echo 'Interest Rate is passed in, storing in nationState and session.';

                        }

                    ?>
                    <br/>
                There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.

                </td>
            </tr>

        </table>
          
    </body>
</html>


 <?php

            function printFormInputBasic(){

                $incomeTax = 0.20;
                if(isset($_SESSION['federalIncomeTax'])){
                    $incomeTax = floatval($_SESSION['federalIncomeTax']);
                }

                $income = 200;
                if(isset($_SESSION['averageIncome'])){
                    $income = intval($_SESSION['averageIncome']);
                }

                echo ' <!-- Input Fields -->
                <form action="game.php" method="post">
               Federal Income Tax(%): <input type="text" name="federalIncomeTax"/ value="'. $incomeTax .'"><br/>
               Average Income($): <input type="text" name="averageIncome" value="'. $income .'"/><br/>
               <input type="submit"/>
                </form>' ;
            }

            //First Landing stuff
            if($_SESSION['firstLanding']=='true'){

                $_SESSION['firstLanding']='false';
                $_SESSION['treasure']=1;
                unset($_SESSION['federalIncomeTax']);
                unset($_SESSION['averageIncome']);

                if(checkValid($_POST['nationName']) == 'true'){
                    $_SESSION['nationName'] = $_POST['nationName'];
                    echo("Hello fellow ruler of the nation by the name of: " . $_SESSION['nationName']);
                }else {
                    echo("Nation Name is not set correctly.");
                    unset($_SESSION['nationName']);
                }
                newLine();

                if(checkValid($_POST['numCitizens']) == 'true'){
                    $_SESSION['numCitizens'] = $_POST['numCitizens'];
                    echo("Your current number of Citizens in the millions is: " . $_SESSION['numCitizens']);
                }else{
                    echo("Num Citizens is not set correctly.");
                    unset($_SESSION['numCitizens']);
                }
                newLine();

                printFormInputBasic();
            }else{

                if(checkValid($_POST['federalIncomeTax']) == 'true'){
                    $_SESSION['federalIncomeTax'] = $_POST['federalIncomeTax'];
                    echo("Federal Income Tax was set as : " . $_SESSION['federalIncomeTax']);
                }else{
                    echo("Federal Income Tax is not readable.");
                    unset($_SESSION['federalIncomeTax']);
                }
                newLine();

                if(checkValid($_POST['averageIncome']) == 'true'){
                    $_SESSION['averageIncome'] = $_POST['averageIncome'];
                    echo("Average Income was set as : $" . $_SESSION['averageIncome']);
                }else{
                    echo("Average Income Tax is not readable.");
                    unset($_SESSION['averageIncome']);
                }
                newLine();

                if(checkValid($_SESSION['averageIncome']) == 'true' && checkValid($_SESSION['federalIncomeTax']) == 'true'){
                    $averageIncome = intval($_SESSION['averageIncome']);
                    $incomeTax = floatval($_SESSION['federalIncomeTax']);
                    $numPeople = intval($_SESSION['numCitizens']);
                    $revenue =   $numPeople * 1000000 * $incomeTax * $averageIncome;

                    echo("Tax Revenue this year : $" . $revenue);
                    newLine();
                    if(checkValid($_SESSION['treasure']) == 'true'){
                        $_SESSION['treasure']+=$revenue;
                        echo("Total Govenment Funds : $" . $_SESSION['treasure']);
                    }else{
                        echo("Treasure is invalid. Thats really bad.");
                    }
                    newLine();
                }

                printFormInputBasic();

           }
           ?>